<#if daoPackage!="">
package ${daoPackage};
</#if>

<#if entityPackage!="">
import ${entityPackage}.${className};
</#if>
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
* Created by ${author} on ${date}.
*/
@Component
public class ${className}DaoImpl implements ${className}Dao {

@Resource
SessionFactory sessionFactory;

public Session getSession() {
return sessionFactory.getCurrentSession();
}

@Override
public ${className} findById(Object id) {
return (${className}) getSession().get(${className}.class, (Serializable) id);
}

@Override
public List<${className}> findAll() {
return getSession().createQuery("from ${className}").list();
}

@Override
public void save(${className} entity) {
getSession().save(entity);
}

@Override
public ${className} update(${className} entity) {
getSession().update(entity);
return entity;
}

@Override
public void delete(${className} entity) {
getSession().delete(entity);
}
}
